<%@page import="study.itwill.team5.board.Comment"%>
<%@page import="study.itwill.team5.board.CommentItem"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%
	String comment_seq = request.getParameter("comment_seq");

	if (!PatternChecker.isValue(comment_seq)) {
		out.print("<script type='text/javascript'>alert('파라미터가 없습니다.');history.back();</script>");
		return;
	}
	if (!PatternChecker.isNum(comment_seq)) {
		out.print("<script type='text/javascript'>alert('파라미터가 부정확합니다.');history.back();</script>");
		return;
	}
	
	int n_comment_seq = Integer.parseInt(comment_seq);

%>
<%@ include file="../dbcon.jsp"%>
<%
	// 덧글목록 받아오기
	Comment comment = new Comment();
	CommentItem item = comment.viewComment(n_comment_seq);
	
	if (item == null) {
		out.print("<script type='text/javascript'>alert('데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.')");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  </head>
  <body>
	<div class="container">
		<form id="frmCommentEdit" class="form-horizontal" role="form" method="post" action="editCommentOk.jsp">
			<input type="hidden" name="comment_seq" value="<%=item.getSeq()%>">
			<input type="hidden" name="board_seq" value="<%=item.getBoard_seq()%>">
			<input type="hidden" name="member_seq" value="<%=item.getMember_seq()%>">
			<fieldset>
				<div class="form-group">
					<label for="member" class="col-md-2 control-label">작성자</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getUser_name()%></p>
					</div>
				</div>
				
				<div class="form-group">
					<label for="comment" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea class="form-control" rows="3" id="comment" name="comment"><%=item.getComment().replace("<br />", "\n")%></textarea>
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
						
					</div>
				</div>
			</fieldset>
		</form>
	</div>

	<% DBHandler.disconnect(); %>
	<script src="/italia/assets/js/jquery.js"></script>
	<script src="/italia/assets/js/bootstrap.min.js"></script>
	<script src="/italia/assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#frmCommentEdit").submit(function() {
				
				// 덧글 입력여부 검사
				if (!$("textarea[name='comment']").val().isValue()) {
					alert("덧글을 입력하세요.");
					$("input[name='comment']").focus();
					return false;
				}
			});
		});
	</script>
	
  </body>
</html>